import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/cupertino.dart';

class AsphereRefreshUtils {
  static refreshWidget(
      {Function? startRefresh,
      Function? startLoad,
      EasyRefreshController? refreshController,
      ScrollController? scrollController,
      required Widget childWidget,
      required BuildContext context}) {
    bool isEnglish = Localizations.localeOf(context).languageCode == 'en';
    return EasyRefresh(
        header: isEnglish
            ? const ClassicHeader(
                showMessage: false,
              )
            : const ClassicHeader(
                readyText: '正在刷新',
                dragText: '下拉刷新',
                showMessage: false,
                armedText: '准备刷新',
                processedText: '成功刷新'),
        footer: isEnglish
            ? const ClassicFooter(
                showMessage: false,
              )
            : const ClassicFooter(
                showMessage: false, processedText: '成功加载', noMoreText: '加载完成'),
        scrollController: scrollController ?? ScrollController(),
        controller: refreshController ?? EasyRefreshController(),
        onRefresh: () async {
          if (startRefresh != null) {
            startRefresh();
          }
        },
        onLoad: () async {
          if (startLoad != null) {
            startLoad();
          }
        },
        child: childWidget);
  }
}
